package com.quick;

import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.quick.api.Result;
import com.quick.exception.QuickException;

import java.util.concurrent.ExecutionException;

@ControllerAdvice
@Configuration
public class GlobalExceptionHandler {
	
	@ResponseBody
	@ExceptionHandler(QuickException.class)
	public Result<Object> quickException(HttpServletResponse response, QuickException ex) {
		ex.printStackTrace();
		return Result.fail(ex.getCode(),ex.getMessage());
	}
	
	@ResponseBody
	@ExceptionHandler(IllegalArgumentException.class)
	public Result<Object> globalException(HttpServletResponse response, IllegalArgumentException ex) {
		ex.printStackTrace();
		return Result.fail(ex.getMessage());
	}

	@ResponseBody
	@ExceptionHandler(ExecutionException.class)
	public Result<Object> globalException(HttpServletResponse response, ExecutionException ex) {
		ex.printStackTrace();
		return Result.fail(ex.getMessage());
	}
	
}
